package com.mall.tag;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspTagException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;

@SuppressWarnings("serial")
public class YNControl extends TagSupport
{
	private String value;
	private String id;
	private String className;
	private String name;
	private String extend;
	private String disable;
	

	public String getValue()
	{
		return value;
	}


	public void setValue(String value)
	{
		this.value = value;
	}


	public String getId()
	{
		return id;
	}


	public void setId(String id)
	{
		this.id = id;
	}


	public String getClassName()
	{
		return className;
	}


	public void setClassName(String className)
	{
		this.className = className;
	}


	public String getName()
	{
		return name;
	}


	public void setName(String name)
	{
		this.name = name;
	}


	public String getExtend()
	{
		return extend;
	}


	public void setExtend(String extend)
	{
		this.extend = extend;
	}


	@Override
	public int doStartTag() throws JspException
	{
		// TODO Auto-generated method stub
		try
		{
			JspWriter out = pageContext.getOut();
			
			//<input type="checkbox" id="${id}" class="${class}" name="${name}" disable="${disable}" value="Y" ${checked}></input>
			String tempString = "<input type=\"checkbox\" id=\"${id}\" class=\"${className}\" name=\"${name}\" disable=\"${disable}\" value=\"Y\" ${checked} ${extend}></input>";
			
			tempString = (id==null?tempString.replaceAll("\\$\\{id\\}", ""):tempString.replaceAll("\\$\\{id\\}", id));
			tempString = (name==null?tempString.replaceAll("\\$\\{name\\}", ""):tempString.replaceAll("\\$\\{name\\}", id));
			tempString = (className==null?tempString.replaceAll("\\$\\{className\\}", ""):tempString.replaceAll("\\$\\{className\\}", id));
			tempString = (disable==null?tempString.replaceAll("\\$\\{disable\\}", ""):tempString.replaceAll("\\$\\{disable\\}", id));
			tempString = (extend==null?tempString.replaceAll("\\$\\{extend\\}", ""):tempString.replaceAll("\\$\\{extend\\}", id));
			tempString = ((value!=null &&value.equals("Y")) ? tempString.replaceAll("\\$\\{checked\\}", "checked=\"checked\""): tempString.replaceAll("\\$\\{checked\\}", ""));
			
			
			out.print(tempString);
			out.flush();
		}
		catch (Exception e)
		{
			// TODO: handle exception
			e.printStackTrace();
			
			throw new JspTagException(e.getMessage());
		}
		
		return SKIP_BODY;
	}

}
